package service;

import bean.Room;
import bean.User;
import dao.DeleteRoomDao;
import dao.DeleteUserDao;
import service.menu.ManagerMenuService;
import service.menu.SuperManagerMenuService;
import util.dbutil.LoginUser;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.Scanner;

public class SuperLoginUserService {
    LoginUser loginUser = new LoginUser();

    public void insertUser(){
        Scanner sc = new Scanner(System.in);

        User user = new User();
        System.out.println("请输入新用户的用户名：");
        String a = sc.next();
        user.setUserName(a);
        System.out.println("请输入新用户的密码：");
        String b = sc.next();
        user.setPassword(b);
        System.out.println("请输入新用户的身份：");
        int c = sc.nextInt();
        user.setRole(c);

        loginUser.insertUser(user);

        System.out.println("输入0返回上一层菜单");
        int y1 = sc.nextInt();
        if (0 == y1) {
            try {
                loginUsers();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        LoginUserService lus = new LoginUserService();
        lus.updateUser();
    }

    public void updateUser(){
        Scanner sc = new Scanner(System.in);

        User user = new User();

        System.out.println("请输入要修改的用户id：");
        int z = sc.nextInt();
        user.setId(z);
        System.out.println("请输入需要修改的新用户名：");
        String a = sc.next();
        user.setUserName(a);
        System.out.println("请输入新的密码：");
        String b = sc.next();
        user.setPassword(b);
        System.out.println("请输入新的身份：");
        int c = sc.nextInt();
        user.setRole(c);

        loginUser.updateUser(user);

        System.out.println("输入0返回上一层菜单");
        int y1 = sc.nextInt();
        if (0 == y1) {
            try {
                loginUsers();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

    }
    public void  loginUsers() throws SQLException, ParseException {
        Scanner sc = new Scanner(System.in);
        LoginUserService lus = new LoginUserService();
        SuperManagerMenuService smms = new SuperManagerMenuService();
        System.out.println("1.添加登录用户\n2.登录用户信息修改\n3.人员删除\n4.人员信息修改\n0.返回上一层菜单");
        int choices = sc.nextInt();
        switch (choices){
            case 1:
                lus.insertUser();
                break;
            case  2:
                lus.updateUser();
                break;
            case 3:
                User user  = new User();
                DeleteUserDao ded = new DeleteUserDao();
                System.out.println("请输入需要删除的用户编号：");
                int a = sc.nextInt();
                user.setId(a);
                ded.deleteUser(user);
                System.out.println("输入0返回上一层菜单");
                int y1 = sc.nextInt();
                if (0 == y1){
                    loginUsers();
                }

                break;
            case  4:
                Room room = new Room();
                DeleteRoomDao drd = new DeleteRoomDao();
                System.out.println("请输入需要删除的房间号：");
                int a1 = sc.nextInt();
                room.setrNumber(a1);
                drd.deleteRoom(room);
                System.out.println("输入0返回上一层菜单");
                int y2 = sc.nextInt();
                if (0 == y2){
                    loginUsers();
                }
                break;
            default:
                smms.superManagerSys();
                break;
        }

    }
}
